/*
 * ========THE SOLMIX PROJECT=====================================
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.gnu.org/licenses/ 
 * or see the FSF site: http://www.fsf.org. 
 */
package org.solmix.fmk.config;

import java.util.Collections;
import java.util.Map;


/**
 * @version $Id$
 */
public class ConfigurationEntry
{

   /**
    * @return the moduleName
    */
   public String getModuleName()
   {
      return moduleName;
   }

   private String moduleName;

   private ModuleControlFlag controlFlag;

   private Map<String, ? > options;

   /**
    * @return the controlFlag
    */
   public ModuleControlFlag getControlFlag()
   {
      return controlFlag;
   }

   /**
    * @return the options
    */
   public Map<String, ? > getOptions()
   {
      return options;
   }



   public ConfigurationEntry(String moduleName, ModuleControlFlag controlFlag, Map<String, ? > options)
   {
      this.controlFlag = controlFlag;
      this.options = Collections.unmodifiableMap(options);
      this.moduleName = moduleName;
      if (moduleName == null
         || moduleName.length() == 0
         || (controlFlag != ModuleControlFlag.REQUIRED && controlFlag != ModuleControlFlag.REQUISITE
            && controlFlag != ModuleControlFlag.SUFFICIENT && controlFlag != ModuleControlFlag.OPTIONAL)
         || options == null)
         throw new IllegalArgumentException();


   }

   public static class ModuleControlFlag
   {
      private String controlFlag;

      /**
       * Required <code>LoginModule</code>.
       */
      public static final ModuleControlFlag REQUIRED = new ModuleControlFlag("required");

      /**
       * Requisite <code>LoginModule</code>.
       */
      public static final ModuleControlFlag REQUISITE = new ModuleControlFlag("requisite");

      /**
       * Sufficient <code>LoginModule</code>.
       */
      public static final ModuleControlFlag SUFFICIENT = new ModuleControlFlag("sufficient");

      /**
       * Optional <code>LoginModule</code>.
       */
      public static final ModuleControlFlag OPTIONAL = new ModuleControlFlag("optional");

      private ModuleControlFlag(String controlFlag)
      {
         this.controlFlag = controlFlag;
      }

      /**
       * Return a String representation of this controlFlag.
       * <p>
       * The String has the format, "ModuleControlFlag: <i>flag</i>", where <i>flag</i> is either <i>required</i>,
       * <i>requisite</i>, <i>sufficient</i>, or <i>optional</i>.
       * 
       * @return a String representation of this controlFlag.
       */
      public String toString()
      {
         return ("ModuleControlFlag: " + controlFlag);
      }
   }
}
